
import networkx as nx

def new_graph(node_total_num):
    g = nx.Graph()
    # pg = nx.path_graph(node_total_num)
    g.add_nodes_from(range(0, node_total_num))
    return g

import copy
def deepcopy_graph( raw_graph ):
    return copy.deepcopy( raw_graph )

def get_subgraphs(cluster_graph):
    subgraph_list = list(nx.connected_component_subgraphs(cluster_graph))
    return subgraph_list

def get_subgraph_num(cluster_graph):
    return len( get_subgraphs(cluster_graph) )

def add_pair_set_to_graph(pair_set_list,cluster_graph ,_weight):
    for pair_set in pair_set_list:
        i, j = list(pair_set)[0], list(pair_set)[1]
        cluster_graph.add_edge(i, j, weight = _weight)
        cluster_graph.add_edge(i, j, )
    return cluster_graph


def get_subgraph_nodes_list(subgraph_list):
    subgraph_nodes_list= []
    for subgraph in subgraph_list:
        subgraph_nodes_list.append( set(subgraph.nodes()) )
    return subgraph_nodes_list

"""
    :param cluster_graph
    :return subgraph_nodes_list, one_node_list, many_node_list
"""
def _subgraph_nodes_list(cluster_graph):
    subgraph_list = get_subgraphs(cluster_graph)
    subgraph_nodes_list = get_subgraph_nodes_list( subgraph_list )
    return subgraph_nodes_list
# old cluster list



def tezt_new_graph():
    g = new_graph(124)
    # [0~123]
    print g.nodes()

if __name__ == '__main__':
    tezt_new_graph()